package com.lili.collection.core.context.impl;

import com.lili.collection.core.context.BatchRecordContext;
import com.lili.collection.core.error.StageRecordException;
import com.lili.collection.core.record.Record;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * 通用批记录上下文
 *
 * @author lili
 * @date 2023/3/7 23:00
 * @description 通用批记录上下文
 */
public class GenericBatchRecordContext implements BatchRecordContext {

    @Getter
    @Setter
    private int index;

    private final List<Record> recordList;

    @Getter
    private final List<Record> errorList;

    @Getter
    @Setter
    private StageContextState stageContextState;

    @Getter
    @Setter
    private StageRecordState stageRecordState;

    @Getter
    @Setter
    private StageRecordException exception;

    public GenericBatchRecordContext() {
        this.index = 0;
        this.recordList = new ArrayList<>();
        this.errorList = new ArrayList<>();
    }

    @Override
    public void setRecord(Record record) {
        recordList.add(record);
    }

    @Override
    public List<Record> getOutput() {
        return recordList;
    }

    @Override
    public void setErrorRecord(Record record) {
        this.errorList.add(record);
    }

    @Override
    public void clearOutput() {
        this.recordList.clear();
    }

    @Override
    public void clear() {
        clearOutput();
        this.errorList.clear();
    }
}
